package com.green.service.common.impl;

import net.spy.memcached.MemcachedClient;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import com.green.dao.cache.XMemcachedCache;



/**
 * XMemcachedCache 
 *
 */
public class XMemcachedCacheImpl implements XMemcachedCache {
	
	private static final Logger LOGGER = Logger	.getLogger(XMemcachedCacheImpl.class);
	@Autowired
	private MemcachedClient memcachedClient;
	@Override
	public boolean add(String s, int i, Object obj) {
		boolean flag=false;
		try {
		    memcachedClient.add(s, i, obj);	
		    flag=true;
		} catch (Exception e) {
			LOGGER.error("Exception",e);
		} 
		return flag;
	}

	@Override
	public boolean delete(String s) {
		boolean flag=false;
		try {
			 memcachedClient.delete(s);
			 flag=true;
		} catch (Exception e) {
			LOGGER.error("Exception",e);
		} 
		return flag;
	}

	@Override
	public Object get(String key) {
		Object obj=null;
		try {
			obj=memcachedClient.get(key);
		
		} catch (Exception e) {
			LOGGER.error("Exception",e);
		} 
		return obj;
	}

	@Override
	public boolean set(String s, int i, Object obj) {
		boolean flag=false;
		try {
		  memcachedClient.set(s, i, obj);
		  flag=true;
		} catch (Exception e) {
			LOGGER.error("Exception",e);
		} 
		 
		return flag;
	}

	@Override
	public boolean replace(String s, int i, Object obj) {
			boolean flag=false;
			try {
			  memcachedClient.replace(s, i, obj);
				 flag=true;
			} catch (Exception e) {
				LOGGER.error("Exception",e);
			} 
		return flag;
	}
	
	
	

}
